import preutils from '@/common/preutils.js'
import check from '@/common/check.js'
import utils from '../../util/printUtils.js'
export default {
	printData: function(outputStream,e) {
		var that = this;
		var text = "";
		var count = 0;
		for(var i = 0 ;i< e.goods.length;i++){
			var item = e.goods[i];
			this.printTitle(outputStream,e,item);
		} 
	},
	
	printTitle: function(outputStream,e,goods) {
		var that = this;
		var text = "";
		var count = Number(goods.goods_nums);
		count = 1;
		text = utils.printConfig(0 ,200 ,200 ,480 ,count);
		text += utils.printPrefeed(10);
		text += utils.printPostfeed(10);
		text += utils.printWidth(570);
		text += utils.printSpeed(1);
		text += utils.printAlign('l');
		//打印边框
		text +=utils.printBox(5,5,570,470,1);
		
		 text += utils.printText('T',4,0,0,0,'');
		text += utils.printSetBoldStart();;
		var memberInfo= uni.getStorageSync(preutils.userinfo)
		// text += utils.printText('T',4,0,20,31,'临沂分拨中心');
		var site_name = check.strNullReplace(memberInfo.site_name,"临沂分拨中心") 
		text += utils.cutLine({x: 20,y: 31}, site_name);
		text += utils.printSetBoldEnd();
		console.log(e)
		//打印线条 横向
		text+=utils.printLine(5,85,380,85,1);

		text += utils.printText('T',3,0,20,111,'收货人：')
		var take_name = check.strNullReplace(e.take_username,"");
		text += utils.printSetBoldStart();
		text += utils.printText('T',3,0,110,111,take_name)
		text += utils.printSetBoldEnd()
		
		//打印线条 横向
		text+=utils.printLine(5,163,380,163,1);
		text += utils.printText('T',3,0,20,189,'到站：')
		var take_city = check.strNullReplace(e.to_city,"") + check.strNullReplace(e.to_county,"");
		text += utils.printSetBoldStart();
		text += utils.printText('T',3,0,90,189,take_city)
		text += utils.printSetBoldEnd()
		
		//打印线条 竖向
		text+=utils.printLine(380,5,380,241,1);
		var qrcontext = "https://3plapidev1.chengxin56.net/weixinArrive/"
					+"?waybill_type=2&waybill_sn="+e.waybill_sn
					+"&waybill_id="+e.waybill_id;
		//二维码
		text += utils.printQr(395,20,2,4,qrcontext); 
		
		text += utils.printText('T',3,0,400,195,'扫码查询运单')
		
		//打印线条 横向
		text+=utils.printLine(5,241,570,241,1);
		text += utils.printText('T',3,0,20,267,"单号：")
		var waybill_sn = check.strNullReplace(e.waybill_sn,"");
		text += utils.printSetBoldStart();
		text += utils.printText('T',3,0,90,267,waybill_sn)
		text += utils.printSetBoldEnd()
		
		//打印线条 横向
		text+=utils.printLine(5,319,570,319,1);
		text += utils.printText('T',3,0,20,345,'货名：')
		var goodsName = check.strNullReplace(goods.goods_name,"");
		text += utils.printSetBoldStart();
		text += utils.printText('T',3,0,90,345,goodsName)
		text += utils.printSetBoldEnd()
		
		//打印线条 横向
		text+=utils.printLine(5,397,570,397,1);
		text += utils.printText('T',3,0,20,423,'总件数：')
		text += utils.printSetBoldStart();
		text += utils.printText('T',3,0,110,423,count)
		text += utils.printSetBoldEnd()
		
		//打印线条 竖向
		text+=utils.printLine(280,397,280,470,1);
		text += utils.printText('T',3,0,290,423,'货签：')
		text += utils.printSetBoldStart();
		text += utils.printText('T',3,0,360,423,1)
		text += utils.printSetBoldEnd()
		text += utils.printCount(1)
		text += utils.printEnd();
		text += utils.print();
		console.log(text)
		var arrayBuffer = plus.android.invoke(text, 'getBytes', 'gbk');
		outputStream.write(arrayBuffer);
		outputStream.flush();
	},
}